package com.material.c2c.web.commodity.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cpt.framework.web.JsonResult;
import com.material.c2c.commodity.service.CommInfoService;
import com.material.c2c.web.commodity.model.CommQuery;

@RestController
@RequestMapping("/index")
public class IndexController {
	@Resource
	private CommInfoService commInfoService;
	
	/**
	 * 获取首页信息
	 * @return
	 */
	@GetMapping("/getIndex")
	public JsonResult getIndex() {
		List<String> flList = new ArrayList<String>();
		flList.add("1");
		flList.add("2");
		flList.add("3");
		flList.add("4");
		flList.add("5");
		return JsonResult.success(commInfoService.getIndex(flList));
	}
	/**
	 * 特价商品
	 * @return
	 */
	@GetMapping("/getTjList")
	public JsonResult getTjList() {
		return JsonResult.success(commInfoService.getTjList());
	}
	/**
	 * 积分商品
	 * @return
	 */
	@GetMapping("/getJfList")
	public JsonResult getJfList() {
		return JsonResult.success(commInfoService.getJfList());
	}
	/**
	 * 某分类商品
	 * @param fl
	 * @return
	 */
	@GetMapping("/getFlList/{fl}")
	public JsonResult getFlList(@PathVariable String fl) {
		return JsonResult.success(commInfoService.getFlList(fl));
	}
	/**
	 * 点击分类时查询的商品
	 * @param query
	 * @return
	 * @since 1.0
	 * @version 1.0
	 */
	@PostMapping("/getFlPage")
	public JsonResult getFlPage(@RequestBody CommQuery query) {
		return JsonResult.success(commInfoService.classifyPage(query.getFl(), query.getPageable()));
	}
	/**
	 * 前台搜索框数据查询表
	 * @param query
	 * @return
	 * @since 1.0
	 * @version 1.0
	 */
	@PostMapping("/search")
	public JsonResult search(@RequestBody CommQuery query) {
		return JsonResult.success(commInfoService.search(query.getKey(), query.getFl(), query.getPageable()));
	}
}
